﻿<template>
  <div id="app">
    <mt-header :title="pageTitle" fixed>
      <a slot="left" @click="goBack" v-show="goBackBtn">
        <mt-button icon="back"></mt-button>
      </a>
    </mt-header>
    <!-- <img src="./assets/logo.png"> -->
    <transition :name="transitionName">
      <router-view class="view_box_cont"/>
    </transition>
  </div>
</template>

<script>
  import { Header  } from 'mint-ui'
  export default {
    components:{Header},
    name: 'App',
    data(){
      return{
        transitionName:'',
        pageTitle:'主页',
        goBackBtn:false
      }
    },
    methods:{
      goBack(){
        history.back(-1);
      }
    },
    watch:{
      $route(to,from){
        this.pageTitle = to.meta.title;
        if(to.meta.title == '主页'){
          this.goBackBtn = false;
        }else{
          this.goBackBtn = true;
        }
        if(to.meta.index > from.meta.index){
        //设置动画名称
          this.transitionName = 'slide-left';
        }else{
          this.transitionName = 'slide-right';
        }
      },
    }

  }
</script>

<style>
*{margin: 0;padding: 0;}
html,body{height: 100%;}
#app {
  text-align: center;
  color: #2c3e50;
  height: 100%;
  overflow: auto;
}
.mint-cell-wrapper{background-image:none;padding: 0 3px; border-bottom: 1px solid #f4f4f4;}
.view_box_cont{margin-top:42px;}
/* 路由跳转时的动画 */
.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  will-change: transform;
  transition: all 500ms;
  position: absolute;width: 100%;
}
.slide-right-enter {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}
.slide-right-leave-active {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
.slide-left-enter {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
.slide-left-leave-active {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}
</style>
